﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics;
using MINERP.MODEL.FoundationModel;
using MINERP.COM;

namespace MINERP.ComControls.Froms
{
    public partial class FrmLookSelftPerformance : Form
    {
        private NewPerformanceBLL _bll;
        private FrmLookSelftPerformance()
        {
            InitializeComponent();
            _bll = new NewPerformanceBLL();
        }

        private static FrmLookSelftPerformance _instance;

        public static FrmLookSelftPerformance GetInstance
        {
            get
            {
                if (_instance == null || _instance.Disposing)
                {
                    _instance = new FrmLookSelftPerformance();
                }

                return _instance;
            }
        }


        //查询的当前操作员的ID
        public int CurUserId { get; set; }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (dtStart.DateTime > dtEnd.DateTime)
            {
                MessageBox.Show("起始日期必须小于结束日期");
                dtStart.DateTime = dtEnd.DateTime.Date;
                return;
            }
            if (CurUserId <= 0)
            {
                MessageBox.Show("没有当前用户");
                return;
            }

            //List<NewPerformanceInfo> resultList = _bll.GetHistoryFilter(CurUserId，dtStart.DateTime.Date, dtEnd.DateTime.Date);
            //gcEmployeePerformance.DataSource = null;

            //if (resultList != null)
            //{
            //    gcEmployeePerformance.DataSource = resultList;
            //    gcEmployeePerformance.RefreshDataSource();

            //    //提交的
            //    //面积数
            //    lblPutInAreas.Text = "提交面积：" + resultList.Sum(em => em.PreOrderArea).ToString("0.0000") + "（㎡）";
            //    //照片数
            //    lblPutInPhotoTotalNum.Text = "提交张数：" + resultList.Sum(em => em.PhotoTotalNum);
            //    //单页数
            //    lblPutInoSinglePageNum.Text = "提交单页:" + resultList.Sum(em => em.SinglePageNum);
            //    //跨页数
            //    lblPutInoMultiplePageNum.Text = "提交跨页：" + resultList.Sum(em => em.MultiplePageNum);


            //    //完成的
            //    //面积数
            //    this.lblOverAreas.Text = "结单面积：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.PreOrderArea).ToString("0.0000") + "（㎡）";
            //    //照片数
            //    this.lblOverPhotoTotalNum.Text = "结单张数：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.PhotoTotalNum);
            //    //单页数
            //    lblOverSinglePageNum.Text = "结单单页:" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.SinglePageNum);
            //    //跨页数
            //    lblOverMultiplePageNum.Text = "结单跨页：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.MultiplePageNum);

            //}
            //else
            //{
            //    MessageBox.Show("此时间段未找到业绩，请重新输入时间再查看！");
            //}
            DataTable table=_bll.GetHistoryFilter(CurUserId,dtStart.DateTime,dtEnd.DateTime);
            ////提交的
            ////面积数
            //lblPutInAreas.Text = "提交面积：" + table.Rows;gridView1.GroupSummary.View
            ////照片数
            //lblPutInPhotoTotalNum.Text = "提交张数：" + resultList.Sum(em => em.PhotoTotalNum);
            ////单页数
            //lblPutInoSinglePageNum.Text = "提交单页:" + resultList.Sum(em => em.SinglePageNum);
            ////跨页数
            //lblPutInoMultiplePageNum.Text = "提交跨页：" + resultList.Sum(em => em.MultiplePageNum);


            ////完成的
            ////面积数
            //this.lblOverAreas.Text = "结单面积：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.PreOrderArea).ToString("0.0000") + "（㎡）";
            ////照片数
            //this.lblOverPhotoTotalNum.Text = "结单张数：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.PhotoTotalNum);
            ////单页数
            //lblOverSinglePageNum.Text = "结单单页:" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.SinglePageNum);
            ////跨页数
            //lblOverMultiplePageNum.Text = "结单跨页：" + resultList.Where(em => em.Status == (int)OrderInfoStatus.Completed).Sum(em => em.MultiplePageNum);

            gcEmployeePerformance.DataSource = table;
            gcEmployeePerformance.RefreshDataSource();
        }

        private void FrmLookSelftPerformance_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }

        private void FrmLookSelftPerformance_Load(object sender, EventArgs e)
        {
            //初始化时间就是当天
            dtStart.DateTime = DateTime.Now.Date;
            dtEnd.DateTime = DateTime.Now.AddDays(1).Date;
        }

        private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            //if (e.RowHandle > -1)
            //{
            //    string status = Convert.ToString(((DataRowView)(gridView1.GetRow(e.RowHandle)))["Status"]);
            //    if ("已删除".Equals(status))
            //    {
            //        e.Appearance.BackColor = Color.Red;//被删除的
            //    }

            //    else if ("已完成".Equals(status) || "正常生产".Equals(status))
            //    {
            //        e.Appearance.BackColor = Color.YellowGreen;
            //    }

            //}
        }

        private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
        {
            var selectR = gridView1.GetFocusedRow() as NewPerformanceInfo;
            if (selectR != null)
            {
                MINERP.BLL.Common.FileBLL.OpenFoler(selectR.OrderPath);
            }

        }
    }
}
